package com.wfs.suanfa.thread;

import java.util.concurrent.*;

/**
 * @author: wfs
 * @Date: 2020/8/13 13:31
 * @Description:
 */
public class ThreadExecutorTest {


    /**
     * https://blog.csdn.net/ganfanzhou/article/details/80874552
     * java线程池拒绝策略
     *  1.AbortPolicy 默认 丢弃任务并抛出RejectedExecutionException异常。
     *  2.DiscardPolicy 丢弃任务，但是不抛出异常。如果线程队列已满，则后续提交的任务都会被丢弃，且是静默丢弃。
     *  3.DiscardOldestPolicy 丢弃队列最前面的任务，然后重新提交被拒绝的任务
     *  4.CallerRunsPolicy 由调用线程处理该任务
     *java线程池队列
     * 1.ArrayBlockingQueue 数组型阻塞队列
     * 2.LinkedBlockingQueue 链表型阻塞队列
     * 3.DelayQueue 延时队列
     * 4.SynchronousQueue 同步队列
     * 5.PriorityBlockingQueue 优先阻塞队列
     *
     *
     * java四中线程池分别为
     * 1.newSingleThreadExecutor
     *
     * 2.newFixedThreadPool 固定数量线程池
     *
     * 3.newSingleThreadExecutor
     *
     * 4.newScheduledThreadPool
     */
    public static void main(String[] args) {
        ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(3);
        LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue();
        DelayQueue delayQueue = new DelayQueue();
        SynchronousQueue synchronousQueue = new SynchronousQueue();
        PriorityBlockingQueue priorityBlockingQueue = new PriorityBlockingQueue();


        //核心线程数与最大线程数都为 1  队列 LinkedBlockingQueue
        ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor();

        //核心线程数等于最大线程数 队列使用LinkedBlockingQueue
        ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(1);

        //   return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
        //核心线程数为0，最大线程数为 Integer.MAX_VALUE，存活六十秒，使用的SynchronousQueue对队列
        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();

        // 核心线程数为默认传入的值，最大线程数为 Integer.MAX_VALUE 存活时间为0   队列使用延迟队列DelayedWorkQueue
        ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1);
    }
}
